package cn.edu.ctbu.controller.admin;

import cn.edu.ctbu.entity.Category;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
public class CategoryController {

    @Autowired
    ICategoryService iCategoryService;



    /**
     * 查询分类
     */
    @ApiOperation("查询分类")
    @GetMapping
    public Result<List<Category>> get(String name,Integer type){
        List<Category> list=iCategoryService.get(name,type);
        return Result.success(list);
    }

    /**
     * 是否禁用
     */
    @ApiOperation("启动禁用分类")
    @GetMapping("/status")
    public Result status(Long id){
        iCategoryService.status(id);
        return Result.success();
    }

    /**
     *删除分类
     */
    @ApiOperation("删除分类")
    @DeleteMapping
    public Result del(Long id){
        iCategoryService.del(id);
        return Result.success();
    }

    /**
     * 新增分类
     */
    @ApiOperation("新增分类")
    @PostMapping("/add")
    public Result add(@RequestBody Category category){
        iCategoryService.add(category);
        return Result.success();

    }

    /**
     * 修改分类
     */
    @ApiOperation("修改分类")
    @PutMapping("/put")
    public Result update(@RequestBody Category category){
        iCategoryService.put(category);
        return Result.success();

    }

    /**
     * 根据分类类型查询分类
     */
    @ApiOperation("type查询分类")
    @GetMapping("/type")
    public Result<List<Category>> type(Integer type){
        List<Category> list=iCategoryService.type(type);
        return Result.success(list);
    }
}
